<template>
    <div class="swiper-container swiper1">
        <div class="swiper-wrapper">
            <div class="swiper-slide" v-for="item of banners" :key="item.targetId">
                <img :src="item.imageUrl" alt="">
            </div>
        </div>
    </div>
</template>

<script>
    import Swiper from 'swiper'
    import {getBanner} from "@/api";

    export default {
        name: "FaXianSwiperOne",
        data(){
           return {
               banners:[]
           }
        },
        mounted() {
            getBanner('/banner')
                .then(response=>{
                    this.banners = response.data.banners
                })
        },
        updated() {
            //原先banners为空，不需要轮播，当数据从后端获取到，并修改了banners后，再开始轮播
            new Swiper('.swiper1', {
                autoplay:true,
                loop:true
            });
        },
        methods:{

        }
    }

</script>

<style scoped>
    .swiper-slide>img{
        width: 100%;
    }
    .swiper-container{
        width: 94%;
        border-radius: 10px;
    }
</style>